package com.learn.mvc.interceptor;


import org.springframework.web.servlet.HandlerInterceptor;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor1 implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String user = (String) request.getSession().getAttribute("user");
        if (StringUtils.isEmpty(user)) {
            // request.getRequestDispatcher("/login").forward(request,response);
            response.sendRedirect("/demo/login");
            return false;
        }
        return true;
    }

}
